package sort;

/**
 * 快速排序
 * https://www.cnblogs.com/xiaoming0601/p/5862860.html
 * Created by JiaJia on 2019/8/15 0015.
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] nums={5,1,6,3,11,7,9,2,13};
        quickSort(nums,0,nums.length-1);
        for (int i = 0; i <nums.length ; i++) {
            System.out.println(nums[i]);
        }
    }
    private static int getMiddle(int[] nums,int low,int high){
        int tmp=nums[low];
        while (low<high){
            while (low<high&&nums[high]>tmp){
                high--;
            }
            nums[low]=nums[high];
            while (low<high&&nums[low]<tmp){
                low++;
            }
            nums[high]=nums[low];
        }
        nums[low]=tmp;
        return low;

    }
    private static void quickSort(int[] nums,int low,int high){
        if (low<high){
            int middle=getMiddle(nums,low,high);
            quickSort(nums,low,middle-1);
            quickSort(nums,middle+1,high);
        }

    }



}